```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ消息过滤机制详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            margin-top: 1.5em;
            margin-bottom: 0.8em;
            color: #111;
        }
        .hero {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            color: white;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        pre {
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 0.5rem;
            padding: 1rem;
            overflow-x: auto;
        }
        code {
            font-family: 'Menlo', 'Monaco', 'Consolas', 'Courier New', monospace;
            background-color: #edf2f7;
            padding: 0.2rem 0.4rem;
            border-radius: 0.25rem;
            color: #4a5568;
        }
        .pros-cons {
            border-left: 4px solid;
            padding-left: 1rem;
        }
        .pros {
            border-color: #48bb78;
        }
        .cons {
            border-color: #f56565;
        }
        .tag {
            display: inline-block;
            background-color: #4299e1;
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            margin-right: 0.5rem;
            margin-bottom: 0.5rem;
        }
        .highlight-box {
            background-color: #f7fafc;
            border-left: 4px solid #4299e1;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 0 0.5rem 0.5rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">RocketMQ消息过滤机制</h1>
            <p class="text-xl md:text-2xl text-blue-100 mb-8">深入解析消息过滤的设计原理、实现方式与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <span class="tag">Tag过滤</span>
                <span class="tag bg-purple-500">SQL过滤</span>
                <span class="tag bg-green-500">性能优化</span>
                <span class="tag bg-yellow-500">最佳实践</span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-blue-100 p-3 rounded-full">
                            <i class="fas fa-filter text-blue-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">消息过滤概述</h2>
                    </div>
                    <p class="text-gray-700 mb-6">
                        在分布式消息系统中，有效的消息过滤机制可以显著提升系统性能和资源利用率。RocketMQ提供了多种过滤方式，从简单的Tag过滤到复杂的SQL表达式过滤，再到完全自定义的过滤逻辑，满足了不同业务场景的需求。
                    </p>
                    <div class="mermaid">
                        graph TD
                            A[消息过滤机制] --> B[Tag过滤]
                            A --> C[SQL过滤]
                            A --> D[自定义过滤]
                            B --> E[简单高效]
                            B --> F[单标签匹配]
                            C --> G[复杂条件]
                            C --> H[多属性过滤]
                            D --> I[完全自定义]
                            D --> J[业务逻辑过滤]
                    </div>
                </div>
            </div>
        </section>

        <!-- Tag Filtering -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-blue-100 p-3 rounded-full">
                            <i class="fas fa-tag text-blue-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">基于Tag的消息过滤机制</h2>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">Tag过滤的基本概念</h3>
                    <p class="text-gray-700 mb-6">
                        Tag是RocketMQ提供的一种轻量级消息过滤机制，它是附加在Topic之上的二级分类，允许消费者在订阅Topic时只接收感兴趣的消息子集，从而减少不必要的消息处理。
                    </p>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">Tag的设计原理</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-paper-plane text-blue-500 mr-2"></i>
                                <h4 class="font-semibold">消息发送端</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>Producer在创建消息时设置Tag属性</li>
                                <li>Tag实际上是消息属性的一部分</li>
                                <li>一条消息只能有一个Tag</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-database text-blue-500 mr-2"></i>
                                <h4 class="font-semibold">消息存储</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>Tag与消息一起写入CommitLog</li>
                                <li>不会影响存储结构</li>
                                <li>tagsCode字段存储哈希值</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-filter text-blue-500 mr-2"></i>
                                <h4 class="font-semibold">过滤实现</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>利用tagsCode实现初步过滤</li>
                                <li>简单条件在Broker端完成</li>
                                <li>复杂条件在Consumer端二次过滤</li>
                            </ul>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">Tag过滤使用示例</h3>
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">Producer设置Tag</h4>
                            <pre><code class="language-java">// 创建消息并指定Tag
Message msg = new Message("TopicTest", "TagA", 
    "Hello RocketMQ".getBytes());
producer.send(msg);

// 同一个Topic下发送不同Tag的消息
Message msg1 = new Message("TopicTest", "TagB", 
    "Another message".getBytes());
producer.send(msg1);</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">Consumer订阅指定Tag</h4>
                            <pre><code class="language-java">// 订阅单个Tag
consumer.subscribe("TopicTest", "TagA");

// 订阅多个Tag(以||分隔)
consumer.subscribe("TopicTest", "TagA || TagB");

// 订阅所有消息，不过滤
consumer.subscribe("TopicTest", "*");</code></pre>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">Tag过滤的优缺点</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="pros-cons pros">
                            <h4 class="font-semibold mb-3 text-green-700 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>优点
                            </h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li>实现简单，使用方便</li>
                                <li>性能影响小，过滤效率高</li>
                                <li>大部分场景能在Broker端完成过滤</li>
                            </ul>
                        </div>
                        <div class="pros-cons cons">
                            <h4 class="font-semibold mb-3 text-red-700 flex items-center">
                                <i class="fas fa-exclamation-circle mr-2"></i>缺点
                            </h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li>过滤能力有限，仅支持简单匹配</li>
                                <li>一个消息只能有一个Tag</li>
                                <li>多Tag订阅时可能降低效率</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- SQL Filtering -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-purple-100 p-3 rounded-full">
                            <i class="fas fa-database text-purple-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">基于SQL表达式的过滤方法</h2>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">SQL过滤的基本概念</h3>
                    <p class="text-gray-700 mb-6">
                        SQL过滤是RocketMQ提供的一种高级消息过滤机制，它允许消费者使用类SQL语法基于消息属性进行复杂的过滤条件表达。
                    </p>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">SQL过滤的实现原理</h3>
                    <div class="highlight-box mb-6">
                        <div class="mermaid">
                            graph LR
                                P[Producer设置属性] --> S[消息存储]
                                S --> C[Consumer订阅SQL表达式]
                                C --> B[Broker解析表达式]
                                B --> F[应用过滤条件]
                                F --> D[返回匹配消息]
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">SQL过滤语法规则</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-equals text-purple-500 mr-2"></i>
                                <h4 class="font-semibold">运算符</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>数值比较: >, >=, <, <=, =, !=</li>
                                <li>字符串比较: =, !=, IS NULL</li>
                                <li>逻辑运算: AND, OR, NOT</li>
                                <li>括号改变优先级</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-code text-purple-500 mr-2"></i>
                                <h4 class="font-semibold">表达式示例</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>a > 5 AND b = 'abc'</li>
                                <li>(a IS NOT NULL OR b IS NULL)</li>
                                <li>a IN (1, 2, 3)</li>
                            </ul>
                        </div>
                        <div class="bg-gray-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-exclamation-triangle text-purple-500 mr-2"></i>
                                <h4 class="font-semibold">限制条件</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>只能基于消息属性</li>
                                <li>表达式复杂度有限制</li>
                                <li>字符串比较区分大小写</li>
                            </ul>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">SQL过滤使用示例</h3>
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">Producer设置属性</h4>
                            <pre><code class="language-java">Message msg = new Message("TopicTest", "TagA", 
    "Hello RocketMQ".getBytes());

// 设置自定义属性
msg.putUserProperty("a", "10");
msg.putUserProperty("b", "ABC");
msg.putUserProperty("c", "true");

producer.send(msg);</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">Consumer使用SQL过滤</h4>
                            <pre><code class="language-java">// 基于属性进行SQL过滤
consumer.subscribe("TopicTest", 
    MessageSelector.bySql("a > 5 AND b = 'ABC'"));

// 结合Tag和SQL进行过滤
consumer.subscribe("TopicTest", 
    MessageSelector.bySql("TagA AND a > 5"));</code></pre>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">SQL过滤的优缺点</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="pros-cons pros border-green-200">
                            <h4 class="font-semibold mb-3 text-green-700 flex items-center">
                                <i class="fas fa-check-circle mr-2"></i>优点
                            </h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li>支持复杂的过滤条件</li>
                                <li>可基于多个消息属性组合</li>
                                <li>支持多种操作类型</li>
                            </ul>
                        </div>
                        <div class="pros-cons cons border-red-200">
                            <h4 class="font-semibold mb-3 text-red-700 flex items-center">
                                <i class="fas fa-exclamation-circle mr-2"></i>缺点
                            </h4>
                            <ul class="list-disc pl-5 space-y-1">
                                <li>性能开销较大</li>
                                <li>需要额外配置</li>
                                <li>增加Broker负担</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Comparison -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-green-100 p-3 rounded-full">
                            <i class="fas fa-tachometer-alt text-green-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">不同过滤方式的性能和适用场景</h2>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">性能对比分析</h3>
                    <div class="overflow-x-auto mb-6">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">性能指标</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Tag过滤</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">SQL过滤</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Consumer端过滤</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">过滤效率</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">Broker负载</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">网络传输量</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">少</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">少</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">CPU使用率</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低/高</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">内存使用率</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                </tr>
                                <tr>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">实现复杂度</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">简单</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">复杂</td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">简单</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">不同场景下的选择指南</h3>
                    <div class="grid md:grid-cols-3 gap-6 mb-6">
                        <div class="bg-blue-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-tag text-blue-600 mr-2"></i>
                                <h4 class="font-semibold">Tag过滤适用场景</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>简单的消息分类需求</li>
                                <li>消息分类维度单一</li>
                                <li>高性能、高吞吐量系统</li>
                                <li>过滤条件固定</li>
                            </ul>
                        </div>
                        <div class="bg-purple-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-database text-purple-600 mr-2"></i>
                                <h4 class="font-semibold">SQL过滤适用场景</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>复杂的过滤条件</li>
                                <li>多维度消息属性过滤</li>
                                <li>动态变化的过滤条件</li>
                                <li>对网络带宽敏感</li>
                            </ul>
                        </div>
                        <div class="bg-green-50 p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-laptop-code text-green-600 mr-2"></i>
                                <h4 class="font-semibold">Consumer端过滤</h4>
                            </div>
                            <ul class="list-disc pl-5 space-y-1 text-gray-700">
                                <li>极其复杂的过滤逻辑</li>
                                <li>需要访问消息体内容</li>
                                <li>过滤逻辑频繁变更</li>
                                <li>Broker资源有限</li>
                            </ul>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">混合过滤策略</h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-layer-group text-yellow-600 mr-2"></i>
                                <h4 class="font-semibold">粗粒度+细粒度过滤</h4>
                            </div>
                            <p class="text-gray-700">
                                使用Tag进行粗粒度的初步过滤，对需要精细过滤的场景，再使用SQL过滤或Consumer端过滤。
                            </p>
                        </div>
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-sitemap text-yellow-600 mr-2"></i>
                                <h4 class="font-semibold">多级过滤</h4>
                            </div>
                            <p class="text-gray-700">
                                Broker端完成基础过滤(Tag或简单SQL)，Consumer端实现更复杂的业务规则过滤。
                            </p>
                        </div>
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-sliders-h text-yellow-600 mr-2"></i>
                                <h4 class="font-semibold">动态调整策略</h4>
                            </div>
                            <p class="text-gray-700">
                                根据系统负载情况动态调整过滤位置，高峰期可将部分过滤逻辑从Broker转移到Consumer。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Custom Filter -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-yellow-100 p-3 rounded-full">
                            <i class="fas fa-code text-yellow-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">自定义过滤器实现</h2>
                    </div>
                    
                    <p class="text-gray-700 mb-6">
                        除了内置的Tag和SQL过滤机制，RocketMQ还支持开发人员实现自定义过滤器，以满足特殊的业务需求。
                    </p>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">过滤器接口定义</h3>
                    <pre class="mb-6"><code class="language-java">public interface MessageFilter {
    boolean match(MessageExt msg, FilterContext context);
}</code></pre>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">实现自定义过滤器</h3>
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">定义过滤器类</h4>
                            <pre><code class="language-java">public class MyMessageFilter implements MessageFilter {
    @Override
    public boolean match(MessageExt msg, FilterContext context) {
        // 自定义过滤逻辑
        String body = new String(msg.getBody());
        // 例如：只接收包含"important"的消息
        return body.contains("important");
    }
}</code></pre>
                        </div>
                        <div>
                            <h4 class="font-semibold mb-2 text-gray-800">在Consumer中使用</h4>
                            <pre><code class="language-java">DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroup");
consumer.registerMessageListener(new MessageListenerConcurrently() {
    @Override
    public ConsumeConcurrentlyStatus consumeMessage(List&lt;MessageExt&gt; msgs, 
            ConsumeConcurrentlyContext context) {
        // 处理消息
        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }
});

// 设置自定义过滤器
consumer.subscribe("TopicTest", "*", new MyMessageFilter());
consumer.start();</code></pre>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-6 mb-4">注意事项与限制</h3>
                    <div class="bg-red-50 p-4 rounded-lg">
                        <ul class="list-disc pl-5 space-y-1 text-gray-700">
                            <li>自定义过滤器通常在Consumer端执行，会增加Consumer的处理负担</li>
                            <li>与服务端过滤相比，自定义过滤无法减少网络传输量</li>
                            <li>实现复杂的过滤逻辑时要注意性能影响</li>
                            <li>过滤器实现应保持无状态，避免引入线程安全问题</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="flex items-center mb-4">
                        <div class="flex-shrink-0 bg-indigo-100 p-3 rounded-full">
                            <i class="fas fa-star text-indigo-600 text-xl"></i>
                        </div>
                        <h2 class="ml-4 text-2xl font-bold">最佳实践与优化建议</h2>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-xl font-semibold mb-4">Tag过滤优化</h3>
                            <div class="space-y-4">
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <div class="flex items-center justify-center h-6 w-6 rounded-md bg-blue-500 text-white">
                                            <i class="fas fa-lightbulb text-xs"></i>
                                        </div>
                                    </div>
                                    <div class="ml-3">
                                        <h4 class="text-sm font-medium text-gray-900">合理设计Tag</h4>
                                        <p class="mt-1 text-sm text-gray-600">
                                            避免Tag数量过多，一般保持在10个以内；Tag命名简洁明确，反映消息类型；相关消息使用同一Topic不同Tag，而非不同Topic。
                                        </p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <div class="flex items-center justify-center h-6 w-6 rounded-md bg-blue-500 text-white">
                                            <i class="fas fa-lightbulb text-xs"></i>
                                        </div>
                                    </div>
                                    <div class="ml-3">
                                        <h4 class="text-sm font-medium text-gray-900">订阅表达式优化</h4>
                                        <p class="mt-1 text-sm text-gray-600">
                                            尽量使用单个Tag订阅；多Tag订阅时，将高频Tag放在表达式前面；避免频繁修改订阅关系。
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div>
                            <h3 class="text-xl font-semibold mb-4">SQL过滤优化</h3>
                            <div class="space-y-4">
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <div class="flex items-center justify-center h-6 w-6 rounded-md bg-purple-500 text-white">
                                            <i class="fas fa-lightbulb text-xs"></i>
                                        </div>
                                    </div>
                                    <div class="ml-3">
                                        <h4 class="text-sm font-medium text-gray-900">属性设计</h4>
                                        <p class="mt-1 text-sm text-gray-600">
                                            只设置必要的过滤属性；属性名尽量简短；属性值类型选择合适，便于比较操作。
                                        </p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <div class="flex items-center justify-center h-6 w-6 rounded-md bg-purple-500 text-white">
                                            <i class="fas fa-lightbulb text-xs"></i>
                                        </div>
                                    </div>
                                    <div class="ml-3">
                                        <h4 class="text-sm font-medium text-gray-900">表达式优化</h4>
                                        <p class="mt-1 text-sm text-gray-600">
                                            保持SQL表达式简单；高频匹配条件放在表达式前面；利用短路逻辑减少计算量。
                                        </p>
                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex-shrink-0 mt-1">
                                        <div class="flex items-center justify-center h-6 w-6 rounded-md bg-purple-500 text-white">
                                            <i class="fas fa-lightbulb text-xs"></i>
                                        </div>
                                    </div>
                                    <div class="ml-3">
                                        <h4 class="text-sm font-medium text-gray-900">Broker配置</h4>
                                        <p class="mt-1 text-sm text-gray-600">
                                            适当增加过滤线程池大小；监控过滤性能，及时调整相关参数。
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <h3 class="text-xl font-semibold mt-8 mb-4">综合建议</h3>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-map-marker-alt text-indigo-600 mr-2"></i>
                                <h4 class="font-semibold">过滤位置选择</h4>
                            </div>
                            <p class="text-gray-700">
                                过滤率高(大量消息被过滤掉)时，优先在Broker端过滤；过滤逻辑复杂且过滤率低时，考虑在Consumer端过滤。
                            </p>
                        </div>
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-chart-line text-indigo-600 mr-2"></i>
                                <h4 class="font-semibold">性能监控</h4>
                            </div>
                            <p class="text-gray-700">
                                监控过滤前后的消息量；观察过滤对Broker和Consumer性能的影响；建立过滤性能基线。
                            </p>
                        </div>
                        <div class="border p-4 rounded-lg">
                            <div class="flex items-center mb-2">
                                <i class="fas fa-project-diagram text-indigo-600 mr-2"></i>
                                <h4 class="font-semibold">渐进式过滤</h4>
                            </div>
                            <p class="text-gray-700">
                                实现多级过滤，先使用高效过滤方式过滤大部分不需要的消息，再应用更精细的过滤条件。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Conclusion -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                <div class="p-8">
                    <div class="text-center">
                        <div class="mx-auto flex items-center justify-center h-12 w-12 rounded-md bg-blue-100 text-blue-600 mb-4">
                            <i class="fas fa-check text-xl"></i>
                        </div>
                        <h2 class="text-2xl font-bold mb-4">结论</h2>
                        <p class="text-lg text-gray-700 max-w-3xl mx-auto">
                            RocketMQ提供了多种消息过滤机制，从简单的Tag过滤到复杂的SQL表达式过滤，再到完全自定义的过滤逻辑，满足了不同业务场景的需求。选择合适的过滤方式，并进行恰当的优化，可以显著提高消息处理效率，降低系统资源消耗。
                        </p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center justify-center">
                <div class="text-lg font-medium mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors duration-200">
                    http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```